<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>获取当前 localstorage 能够使用的最大大小</title>
	</head>
	<body>
		<p>4、获取当前 localstorage 能够使用的最大大小</p>
	</body>
	<script>
		let testStr = "1234567890";
		let str = "";
		for(let i=0;i<1024;i++){
			str = str + testStr;
		}
		let sum = "";
		let i = 0;
		
		while(i<513){
			i++;
			try{
				sum += str;
				localStorage.removeItem("sum");
				localStorage.setItem("sum",sum);
			}catch(e){
				alert("最大使用量为"+(sum.length / 1024 / 1024).toFixed(2)+"MB...");
				break;	
			}
		}
	</script>
</html>
